package cn.market.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class Util {
	private static String TAG = "Util";
	public static Date getDate(String date){
		if(date == null)
			return null;
		String methodName = "getDate()";
		Log.println(TAG, methodName+" -- the date is:"+date);
		DateFormat convert = new SimpleDateFormat("yyyy-MM-dd");
		try {
			return convert.parse(date);
		} catch (ParseException e) {
			DateFormat convert2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			try {
				return convert2.parse(date);
			} catch (ParseException e1) {}
		}
		return null;
	}
	
	public static String getYear(Date date){
		if(date == null)
			return null;
		DateFormat convert = new SimpleDateFormat("yyyy");
		return convert.format(date);
	}
	public static String getMonth(Date date){
		if(date == null)
			return null;
		DateFormat convert = new SimpleDateFormat("MM");
		return convert.format(date);
	}
	public static String getDay(Date date){
		if(date == null)
			return null;
		DateFormat convert = new SimpleDateFormat("dd");
		return convert.format(date);
	}
}
